<?php
/**
 * 发送邮件的类
 * @author jroam
 *
 */
class sendmailAction extends globalAction
{
	/**
	 * 发送出团通知书页面给客户,需要以url的方式分层协议 递订单号，发送到的邮箱,订单的id
	 */
	function chutuantzs()
	{
			$orderid=$_REQUEST["orderid"];//订单号
			$tomail=ui_huanyuanxiahuax($_REQUEST["tomail"]);//发送到的邮箱
			$oid=$_REQUEST["id"];
			if(!isstri($orderid)) die("订单号不正确");
			if(!ismail($tomail)) die("邮箱地址不正确");
			if(!is_numeric($oid)) die("订单id不正确");
			
			require_once RootDir."/inc/MailClass.php";
			$contenthtml=file_get_contents("http://".$_SERVER['SERVER_NAME']."/affirm".FGF."chutuantongzhi".FGF."orderid".FGF.$orderid);
			
			if(sendmymail($tomail,"mzl","梦之旅提醒您，请查收您的出团通知书",$contenthtml))
			{
				//发送成功更改发送标识
				$ar=A("orderform");
				$data["orderform30"]=1;
				$ar->updatersonefiled("orderform0=".$oid,$data);
				
				alert("/".Syshoutai."/u.php/orderform".FGF."editorder".FGF."id".FGF."".$oid,2,"出团通知书发送成功");
			}
			else
			{
				alert("/".Syshoutai."/u.php/orderform".FGF."editorder".FGF."id".FGF."".$oid,2,"出团通知书发送失败");
			}
			
	}
	/**
	 * 
	 * 发送国内合同
	 */
	function guoleihetong()
	{
			$orderid=$_REQUEST["orderid"];//订单号
			$tomail=ui_huanyuanxiahuax($_REQUEST["tomail"]);//发送到的邮箱
			$oid=$_REQUEST["id"];
			if(!isstri($orderid)) die("订单号不正确");
			if(!ismail($tomail)) die("邮箱地址不正确");
			if(!is_numeric($oid)) die("订单id不正确");
			
			require_once RootDir."/inc/MailClass.php";
			$contenthtml=file_get_contents("http://".$_SERVER['SERVER_NAME']."/affirm".FGF."guoleihetong".FGF."orderid".FGF."".$orderid);
			
			if(sendmymail($tomail,"mzl","梦之旅提醒您，请查收您的旅游合同(订单号:$orderid)",$contenthtml))
			{
				//发送成功更改发送标识
				$ar=A("orderform");
				$data["orderform31"]=1;
				$ar->updatersonefiled("orderform0=".$oid,$data);
				alert("/".Syshoutai."/u.php/orderform".FGF."editorder".FGF."id".FGF."".$oid,2,"旅游合同发送成功");
			}
			else{
				alert("/".Syshoutai."/u.php/orderform".FGF."editorder".FGF."id".FGF.$oid,2,"旅游合同发送失败");
			}
	}
	
/**
	 * 
	 * 发送出境合同
	 */
	function chujinghetong()
	{
			$orderid=$_REQUEST["orderid"];//订单号
			$tomail=ui_huanyuanxiahuax($_REQUEST["tomail"]);//发送到的邮箱
			$oid=$_REQUEST["id"];
			if(!isstri($orderid)) die("订单号不正确");
			if(!ismail($tomail)) die("邮箱地址不正确");
			if(!is_numeric($oid)) die("订单id不正确");
			
			require_once RootDir."/inc/MailClass.php";
			$contenthtml=file_get_contents("http://".$_SERVER['SERVER_NAME']."/affirm".FGF."chujinghetong".FGF."orderid".FGF."".$orderid);
			
			if(sendmymail($tomail,"mzl","梦之旅提醒您，请查收您的旅游合同(订单号:$orderid)",$contenthtml))
			{
				//发送成功更改发送标识
				$ar=A("orderform");
				$data["orderform31"]=1;
				$ar->updatersonefiled("orderform0=".$oid,$data);
				alert("/".Syshoutai."/u.php/orderform".FGF."editorder".FGF."id".FGF."".$oid,2,"旅游合同发送成功");
			}
			else
			{
				alert("/".Syshoutai."/u.php/orderform".FGF."editorder".FGF."id".FGF.$oid,2,"旅游合同发送失败");
			}
	}
	
	/**
	 * 支付成功时发送给客人的邮件内容
	 */
	function paysuss(){
		$orderlist=$_GET["orderlist"];//订单列表，字符串的格式 ：订单号1|支付金额|支付类型,订单号2|支付金额2|支付类型
		
		
		//下面的以后再来弄

		//初始化信息
		preg_match("/^[a-zA-Z][0-9]+/",$orderlist,$ordernoarr);
		$jelistarr=explode(",",$jelist);
		
		
		
		//获取这个订单信息，
		$public=A("public");
		$sql="select * from ".DQ."orderform where orderform3='".$ordernoarr[0]."'";
		$rs=$public->query($sql);
		if($rs){
			$this->assign("rs",$rs[0]);
			$this->assign("paytype",$paytype);
			$this->assign("ordernoarr",$ordernoarr);
			$this->assign("jelistarr",$jelistarr);
			$html=$this->fetch("sendmail:paysuss");//获取邮件内容
			require_once RootDir."/inc/MailClass.php";
			sendmymail($tomail,"梦之旅","梦之旅提醒您,您的订单已经支付成功",$html);
		}
		$this->display();

	}
	
/**
	 * 支付成功时发送给客人的邮件内容
	 */
	function paysusshotel(){
		$orderlist=$_GET["orderno"];//格式H1000000001(a12) a表示是定金,小括号前面的是订单号
		//初始化参数
  		$dingdanno= getsubstr($orderlist, "/^H[\d]+/");
   		$jetype=getkuohaostr($orderlist, "/\(([a-z])/");//如果是a表示支付的是定金,如果是b支付的是余额
	

		//获取这个订单信息，
		$public=M("sendmail");
		$sql="select a.*,c.*,b.hotelroom1 from ".DQ."orderform as a left join ".DQ."hotelroom as b on a.orderform31 =b.hotelroom0
			left join ".DQ."pay as c on a.orderform3=c.pay1
		where orderform3='".$dingdanno."'";
		$rs=$public->query($sql);
		if($rs){
			$this->assign("rs",$rs[0]);
			$this->assign("paytype",$jetype);
			
			//获取相关推荐的产品 目前主要推荐相同地区域酒店信息
			$sql="select * from ".DQ."hotel where 
			hotel5=(select hotel5 from ".DQ."hotel where hotel0=".$rs[0]["orderform1"].") 
				and hotel0<>".$rs[0]["orderform1"]." order by hotel0 desc limit 0,10";
			
			$sql="select hotel0,hotel1,hotel15 from ".DQ."hotel where hotel15<>'' order by hotel0 desc limit 0,10";
			
			$otherrs=$public->query($sql);
			
			$this->assign("otherrs",$otherrs);
			$html=$this->fetch("sendmail:paysusshotel");//获取邮件内容
			require_once RootDir."/inc/MailClass.php";
			//如果邮箱正确就发送邮箱
			//if(getsubstr($rs[0]["orderform26"], "/^[\w\-\_\.]+@[\w\-\_\.]+[\w]+$/")) sendmymail($rs[0]["orderform26"],"梦之旅","梦之旅提醒您,您的订单已经支付成功",$html);
		}
		$this->display();

	}
	
	
	
	
	
	/**
	 * 当后台工作人员确认此订单时发送
	 */
	function ReceiveOrder()
	{
		$ordrid=$_REQUEST["orderid"];
		if(!is_numeric($ordrid)) return "";
		$this->display();
	}
	
	/**
	 * 当下客栈订单成功时的发送邮件的html代码
	 */
	function createinnorderhtml(){
		
		$orderno=$_REQUEST["orderno"];//订单号
		$mr=M("sendmail");
		$sql="select *,c.hotelroom1 from ".DQ."orderform as a left join ".DQ."pay as b on a.orderform3=b.pay1
			left join ".DQ."hotelroom as c on a.orderform31=c.hotelroom0
		
		where a.orderform3='".$orderno."'";
		$rs=$mr->query($sql);
		$this->assign("rs",$rs[0]);
		$this->display();
	}
	
	
	
	
}

?>